﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonExtensions.ObjectExtensions;
using CommonExtensions.StringExtensions;
using DBMigrator.Core.DbObjects.Data.Select.From.Join;
using DBMigrator.Core.DbObjects.Data.Where;

namespace DBMigrator.Core.DbObjects.Data.Select.From
{
    public class FromTable : IFromTable
    {
        public string JoinTableName { get; private set; }
        public JoinTypes JoinType { get; private set; }
        public IJoinOn JoinOn { get; private set; }
        public IWhere Where { get; private set; }
        
        public FromTable(IJoinOn joinOn, IWhere where)
        {
            if(joinOn.IsNull())
                throw new ArgumentNullException("joinOn");
            if(where.IsNull())
                throw new ArgumentNullException("where");

            JoinOn = joinOn;
            Where = where;
        }

        public IJoinOn Join(string joinTableName)
        {
            return Join(JoinTypes.Inner, joinTableName);
        }

        public IJoinOn LeftOuterJoin(string joinTableName)
        {
            return Join(JoinTypes.LeftOuter, joinTableName);
        }

        public IJoinOn RightOuterJoin(string joinTableName)
        {
            return Join(JoinTypes.RightOuter, joinTableName);
        }

        public IJoinOn FullOuterJoin(string joinTableName)
        {
            return Join(JoinTypes.FullOuter, joinTableName);
        }

        protected IJoinOn Join(JoinTypes joinType, string joinTableName)
        {
            if(joinTableName.IsBlank())
                throw new ArgumentNullException("joinTableName");

            JoinType = joinType;
            JoinTableName = joinTableName;

            return JoinOn;
        }
    }
}